<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Title</title>
  </head>
  <body>
  
  </body>
  
  <script>
    /*字符串字面量*/
    console.log(typeof 'hhh');//string
    console.log(typeof "hhh");//string
    
    console.log("hhh \'n\'");
    console.log("hhh \\n xxx");
    console.log("hhh \n xxx");
    
    console.log('hhh');
    console.log(typeof 'hhh');//string
    console.log(new String('hhh'));
    console.log(typeof new String('hhh'));//object
    console.log('hhh' == new String('hhh'));//true
    console.log('hhh' === new String('hhh'));//false
    
    
    /*模板字面量*/
    var string1 = 'hhh \n xxx';
    var template1 = `hhh \n xxx`;
    console.log(string1);
    console.log(template1);
    
    var string2 = 'hhh' +
        'xxx';
    var template2 = `hhh
            xxx`;
    console.log(string2);
    console.log(template2);
    
    var name = 'NAME'
    var string3 = 'hhh' + name + 'xxx';
    var template3 = `hhh${name}xxx`;
    console.log(string3);
    console.log(template3);
    
    
    /*数字字面量*/
    console.log(typeof 10);//number
    console.log(typeof 10.12);//number
    console.log(+1.7976931348623159e+308);//Infinity
    
    console.log(new Number('123'));//Number {123}
    console.log(new Number(''));//Number {0}
    console.log(new Number(false));//Number {0}
    console.log(new Number(null));//Number {0}
    console.log(new Number(true));//Number {1}
    console.log(new Number('hhh'));//Number {NaN}
    console.log(new Number(undefined));//Number {NaN}
    
    console.log(10);//10
    console.log(typeof 10);//number
    console.log(new Number(10));//Number {10}
    console.log(typeof new Number(10));//object
    console.log(10 == new Number(10));//true
    console.log(10 === new Number(10));//false
    
    // parseInt相比NUmber来说没那么严格，parseInt会逐个解析字符，遇到没办法解析的则停下来
    console.log(parseInt("32a2")) // 32
    
    
    /*布尔字面量*/
    console.log(typeof true);//boolean
    console.log(typeof false);//boolean
    
    console.log(new Boolean(''));//Boolean {false}
    console.log(new Boolean('string'));//Boolean {true}
    console.log(new Boolean(0));//Boolean {false}
    console.log(new Boolean(NaN));//Boolean {false}
    console.log(new Boolean(100));//Boolean {true}
    console.log(new Boolean(null));//Boolean {false}
    console.log(new Boolean(undefined));//Boolean {false}
    console.log(new Boolean(new Object()))//Boolean {true}
    
    console.log(true);//true
    console.log(typeof true);//boolean
    console.log(new Boolean(true));//Boolean {true}
    console.log(typeof new Boolean(true));//object
    console.log(true == new Boolean(true));//true
    console.log(true === new Boolean(true));//false
    
    
    /*数组字面量*/
    var array1 = [10, 20, 30];
    console.log(array1);//(3) [10, 20, 30]
    console.log(array1[0]);//10
    console.log(array1.length);//3
    
    var array2 = [, 10, 20, , 40, ,];
    console.log(array2);//(6) [空白, 10, 20, 空白, 40, 空白]
    console.log(array2[0]);//undefined
    console.log(array2.length);//6
    
    console.log([10, 20, 30]);//(3) [10, 20, 30]
    console.log(typeof [10, 20, 30]);//object
    console.log(new Array(10, 20, 30));//(3) [10, 20, 30]
    console.log(typeof new Array(10, 20, 30));//object
    console.log([10, 20, 30] == new Array(10, 20, 30));//false
    console.log([10, 20, 30] === new Array(10, 20, 30));//false
    
    
    /*对象字面值*/
    var obj = {
      name: 'name',
      10: 'hhhh',
      "number-1": 10,
      "": '空',
      "!": '!!!!',
      children: {
        name: 'child-name'
      },
    }
    console.log(obj.name);//name
    console.log(obj["name"]);//name
    console.log(obj[name]);//undefine
    
    //console.log(obj.10);//语法错误，书写时给出错误提示
    console.log(obj[10]);//hhhh
    console.log(obj["10"]);//hhhh
    
    //console.log(obj.'number-1');//语法错误，书写时给出错误提示
    console.log(obj['number-1']);//10
    
    //console.log(obj."");//语法错误，书写时给出错误提示
    console.log(obj[""]);//空
    
    //console.log(obj."!");//语法错误，书写时给出错误提示
    console.log(obj["!"]);//!!!!
    
    console.log(obj.children);//{name: 'child-name'}
    console.log(obj["children"]);//{name: 'child-name'}
    //console.log(obj[children]);//Uncaught ReferenceError: children is not defined
    
    console.log(obj.children.name);//child-name
    console.log(obj.children["name"]);//child-name
    console.log(obj["children"].name);//child-name
    console.log(obj["children"]["name"]);//child-name
    
    
    /*RegExp字面值*/
    var reg = /1{3,}/;
    console.log(reg);
    console.log(typeof reg);
    console.log(reg.test('1111'));
    console.log(reg.exec('1111'));
  </script>
</html>